﻿using System.Collections.Generic;
using System.Linq;

namespace Project5188.BUS
{
    public class ParameterValues : DetailView<parametervalue>
    {
        private project5188Entities _context;
        // ReSharper disable InconsistentNaming
        private new List<parametervalue> EntityList;
        private new parametervalue Entity;
        // ReSharper restore InconsistentNaming

        public long TransactionId { get; private set; }

        public override List<parametervalue> GetEntityById(long id)
        {
            _context = new project5188Entities();
            EntityList = _context.parametervalues.Where(a => a.ID == id && !a.IsDeleted).OrderBy(a => a.ID).ToList();
            return EntityList;
        }

        public List<parametervalue> GetEntityByParameterId(long parameterId)
        {
            _context = new project5188Entities();
            EntityList = _context.parametervalues.Where(a => a.ParameterID == parameterId && !a.IsDeleted).OrderBy(a => a.ID).ToList();
            return EntityList;
        }

        public override void Update()
        {
            _context.SaveChanges();
        }

        public override parametervalue GetEntity()
        {
            _context = new project5188Entities();
            Entity = new parametervalue();
            return Entity;
        }

        public override void Insert()
        {
            _context.AddToparametervalues(Entity);
            _context.SaveChanges();
            TransactionId = Entity.ID;
        }

        public override List<parametervalue> GetEntityList()
        {
            _context = new project5188Entities();
            EntityList = _context.parametervalues.Where(a => !a.IsDeleted).OrderBy(a => a.ID).ToList();

            return EntityList;
        }

        public List<parametervalue> GetEntityListByParameters(string parameterValueName)
        {
            _context = new project5188Entities();

            EntityList = _context.parametervalues.Where(a => (a.Value.Contains(parameterValueName)) && !a.IsDeleted).OrderBy(a => a.ID).ToList();

            return EntityList;
        }
    }
}
